/*
 *  F4.h
 *  generic-genetic-algorithm
 *
 *  Created by Srđan Rašić on 12/9/11.
 *  Copyright 2011 __MyCompanyName__. All rights reserved.
 *
 */

#pragma once
#include "Function.h"
#include <utility>
#include <vector>
#include <cmath>

class F4 : public Function {
private:
	std::vector<double> _p;
	
public:
	F4(std::vector<double> p) {
		_p = p;
	}
	virtual double operator() (std::vector<double> vec) const {
		// (x1-p1)^2 + (x2-p2)^2 + ... + (x5-p5)^2
		double value = 0.0;
		
		for (int i = 0; i < 5; i++)
			value += pow(vec[i] - _p[i], 2.0);
		
		return value;
	}
	
	virtual std::pair<double, double> Domain() const {
		return std::make_pair(-100, 100);
	}
	
	virtual unsigned int Dimensions() const {
		return _p.size();
	}
};